#!/usr/bin/python
# -*- coding: UTF-8 -*- 
from sys import argv
def merge_data(d1,d2,d2_off):
    all_bin = d1 + b"\0" * (d2_off-len(d1)) + d2
    return all_bin

def merge_bin(bin1,bin2_off,bin2,f_out):
    with open(bin1,"rb") as f:
        d1 = f.read()

    with open(bin2,"rb") as f:
        d2 = f.read()

    all_bin = merge_data(d1,d2,bin2_off)
    #all_bin = all_bin[:-8192]

    with open(f_out,"wb+") as f:
        f.write(all_bin)    

if __name__ == '__main__':
    #print(argv)
    if(len(argv) < 3):
        print("parm error")
    merge_bin(argv[1],int(argv[2]),argv[3],argv[4])